<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of iReportManager
 *
 * @author Ganda
 */

Yii::import('application.extensions.ireport.*');
include_once(Yii::app()->getBasePath().'/extensions/ireport/class/tcpdf/tcpdf.php');
include_once(Yii::app()->getBasePath().'/extensions/ireport/class/PHPJasperXML.inc.php');

class iReportManager {
    private $server = '';
    private $user = '';
    private $pass = '';
    private $db = '';

    public function __construct(){
        $this->server = explode('=',Yii::app()->db->connectionString);
        $this->server = explode(';', $this->server[1]);
        $this->server = $this->server[0];
        
        $this->db = explode('=',Yii::app()->db->connectionString);
        $this->db = $this->db[2];
        
        $this->user = Yii::app()->db->username;
        $this->pass = Yii::app()->db->password;
    }
    
    public function renderReport($reportfile = '',$params = array()){
        $xml =  simplexml_load_file($reportfile);

        $PHPJasperXML = new PHPJasperXML();
        $PHPJasperXML->arrayParameter=$params;
        $PHPJasperXML->xml_dismantle($xml);


        $PHPJasperXML->transferDBtoArray($this->server,$this->user,$this->pass,$this->db);
        $PHPJasperXML->outpage("I"); //page output method I:standard output  D:Download file
    }
}

?>
